package fr.esiea.es_inf5042.persistance.dao;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

import fr.esiea.es_inf5042.business.*;
import fr.esiea.es_inf5042.persistance.dao.SQLiteDAO.SQLiteDAOFactory;

public abstract class AbstractDAOFactory{

	public abstract DAO<User> getUserDAO();
	public abstract DAO<Bargain> getBargainDAO();
	public abstract DAO<Comment> getCommentDAO();	
		
	public static AbstractDAOFactory getDAOFactory(Context context)
	{
		AbstractDAOFactory factory = null;		
		ApplicationInfo ai = null;		
		String dataAcces = null;
        
		try {
			
			//KSE - Get object which read AndroidManifest.xml attributes from <meta-data> tags.
			ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);					
									
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		//KSE - Get the string representative to database access selection. Key value from AndroidManifest.xml is "Data-Access".
		dataAcces = ai.metaData.getString("Data-Access");
		
		if(dataAcces.equals("SQLite"))			
			factory = new SQLiteDAOFactory(context);
		
		return factory;		
	}
}
